<html>
<head><meta charset="utf-8"><title>type ascription · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html">type ascription</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213852443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213852443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213852443">(Oct 19 2020 at 22:07)</a>:</h4>
<p>Dear <span class="user-group-mention" data-user-group-id="1977">@T-lang</span>, I'd like to take people's temperature on type ascription syntax. I just re-read <a href="https://github.com/rust-lang/rfcs/issues/2623">rfc#2623</a> and I was thinking that it might actually suggest a decent implementation path. So... are there outstanding concerns with <code>x: T</code> as type ascription syntax?</p>
<p>I'm going to try a poll!</p>



<a name="213852460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213852460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213852460">(Oct 19 2020 at 22:07)</a>:</h4>
<p>/poll Type ascription syntax: what say you?</p>



<a name="213853588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213853588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213853588">(Oct 19 2020 at 22:20)</a>:</h4>
<p>I still feel mildly uncomfortable wrt to the effects type ascription has on readability etc -- in particular, it seems to require the <code>(expr): foo</code> pattern and given .await as something that has landed in the meantime, it seems like the wrong thing. IIRC, there's some parser recovery problems with it too.</p>
<p>I have not read the RFC in detail, but I personally am unconvinced that type ascription is necessary. I sometimes want it, but often the extra <code>let</code> temporary wouldn't really hurt (and may even help).</p>



<a name="213855146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213855146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213855146">(Oct 19 2020 at 22:36)</a>:</h4>
<p>I don't think type ascription is very often useful and I'd prefer to save the syntax for keyword args</p>



<a name="213862866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213862866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213862866">(Oct 20 2020 at 00:18)</a>:</h4>
<p>I feel with <code>let x: T</code> existing it's hard to pick any <em>other</em> syntax.</p>
<p>That said, I've pondered making <code>x as T</code> be ascription in an edition change.  We're getting closer and closer to having everything it can do have more targeted library methods instead (<code>.cast()</code> on pointers, <code>transmute!</code>, <code>.into()</code>, etc).  So that would potentially open up that syntax instead.</p>



<a name="213863167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213863167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213863167">(Oct 20 2020 at 00:22)</a>:</h4>
<p>At the very least, we could have a lint for "you used <code>as</code> for something that isn't a simple ascription", and use an edition to ramp it to warn.</p>



<a name="213863690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213863690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213863690">(Oct 20 2020 at 00:29)</a>:</h4>
<p>clippy has this one, though it's allow-by-default right now:</p>
<div class="codehilite"><pre><span></span><code>warning: using a potentially dangerous silent `as` conversion
 --&gt; src/main.rs:3:13
  |
3 |     let _ = 123_i32 as u64;
  |             ^^^^^^^^^^^^^^
  |
  = help: consider using a safe wrapper for this conversion
</code></pre></div>



<a name="213863814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213863814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213863814">(Oct 20 2020 at 00:31)</a>:</h4>
<p>I should go push on that <code>WrappingFrom</code> RFC...</p>



<a name="213868914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213868914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213868914">(Oct 20 2020 at 02:17)</a>:</h4>
<p>I guess it's too late to suggest the solution used in lean, which is to make the parentheses in <code>(e: T)</code> a mandatory part of the syntax</p>



<a name="213869077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213869077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213869077">(Oct 20 2020 at 02:20)</a>:</h4>
<p>I use type ascription all the time in lean and miss it dearly in rust. But in particular it is definitely used to trigger coercions, in fact that's the main reason to put them in, and the RFC seems like it's going to kill non-trivial use of the type ascription operator</p>



<a name="213869439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213869439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213869439">(Oct 20 2020 at 02:29)</a>:</h4>
<p>I would be happy for <code>e as T</code> to take on the role of type ascription too. But clippy has an annoying lint for this: if you write <code>e as T</code> when you should have written <code>e: T</code> (or maybe <code>coerce e</code>? what the hell am I supposed to write!), it gives a warning saying you should write explicit temporaries, which is silly, as it makes coercion <em>more</em> verbose than just calling a function</p>



<a name="213869777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213869777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213869777">(Oct 20 2020 at 02:36)</a>:</h4>
<p>By the way a side benefit of mandatory parentheses is that it solves all the problems around associativity, given all the prefix and postfix operators in rust. It seems good to be explicit if you are type-ascribing an expression to say which part you are talking about</p>



<a name="213879373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213879373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213879373">(Oct 20 2020 at 06:33)</a>:</h4>
<p>Half the time I would want ascription, I'm at the end of an expression and having to wrap it in parens would be annoying.</p>



<a name="213880070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213880070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213880070">(Oct 20 2020 at 06:45)</a>:</h4>
<p>why at the end of an expression? Use cases differ across languages, but I often find myself using type ascription in lean to key the type so I can call a method, i.e. <code>(e: T).method()</code></p>



<a name="213880198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213880198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213880198">(Oct 20 2020 at 06:47)</a>:</h4>
<p>in rust it's mostly when I want an explicit coercion, although occasionally it's more ergonomic than supplying type parameters (and I guess that's the use case most here are thinking about)</p>



<a name="213880816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213880816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213880816">(Oct 20 2020 at 06:57)</a>:</h4>
<p>If you are at the end of an expression, it seems like you would almost always have a place to put the type: if it is <code>let x = expr;</code> you can put the type on <code>x</code> instead of <code>expr</code> and if it's a return expression then the outer context is supplying the type. But when you are in the middle of an expression there isn't any place to put the type, especially if you are invoking a coercion because those have no syntax</p>



<a name="213881321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881321">(Oct 20 2020 at 07:05)</a>:</h4>
<p>End of an expression, not end of a statement.</p>



<a name="213881401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881401">(Oct 20 2020 at 07:06)</a>:</h4>
<p>Cases where I want ascription include return-type inference within a chain, for instance.</p>



<a name="213881450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881450">(Oct 20 2020 at 07:07)</a>:</h4>
<p>Forced parentheses have the same problem that <code>try!</code> did: it piles up on the front of the expression.</p>



<a name="213881579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881579">(Oct 20 2020 at 07:09)</a>:</h4>
<p>Suppose I want to write <code>A::b(...).c(...).d(...).e(...)</code>, except I need ascription in one or two places before a call.</p>



<a name="213881633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881633">(Oct 20 2020 at 07:10)</a>:</h4>
<p>I would have to go back to the start of the chain and add a(nother) layer of parens.</p>



<a name="213881833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881833">(Oct 20 2020 at 07:13)</a>:</h4>
<p>I don't see how you can do better than this with infix <code>e : T</code> or <code>e as T</code> though</p>



<a name="213881859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881859">(Oct 20 2020 at 07:13)</a>:</h4>
<p>if it was <code>e.ascr(T)</code> then ok</p>



<a name="213881905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881905">(Oct 20 2020 at 07:14)</a>:</h4>
<p>but that's kind of weird</p>



<a name="213881983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213881983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213881983">(Oct 20 2020 at 07:15)</a>:</h4>
<p>I think it's easier to use <code>let</code> in that situation though because it's very linear</p>



<a name="213882000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213882000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213882000">(Oct 20 2020 at 07:15)</a>:</h4>
<p>it's more annoying to use let when it turns your expression tree inside out</p>



<a name="213882058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213882058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213882058">(Oct 20 2020 at 07:16)</a>:</h4>
<p>... That gives me an idea...</p>



<a name="213882070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213882070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213882070">(Oct 20 2020 at 07:16)</a>:</h4>
<p>/me tries something on the playground.</p>



<a name="213883294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883294">(Oct 20 2020 at 07:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/213881859">said</a>:</p>
<blockquote>
<p>if it was <code>e.ascr(T)</code> then ok</p>
</blockquote>
<p><code>e.as(T)</code>?</p>



<a name="213883328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883328">(Oct 20 2020 at 07:31)</a>:</h4>
<p>is this the same as <code>e as T</code>, semantically?</p>



<a name="213883374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883374">(Oct 20 2020 at 07:32)</a>:</h4>
<p>or is it only coercion</p>



<a name="213883462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883462">(Oct 20 2020 at 07:33)</a>:</h4>
<p>I'm just suggesting a syntax without chaining problems here, not semantics.</p>



<a name="213883477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883477">(Oct 20 2020 at 07:33)</a>:</h4>
<p>But there was a suggestion to turn <code>as</code> into a type ascription above.</p>



<a name="213883480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883480">(Oct 20 2020 at 07:33)</a>:</h4>
<p>Couldn't get this to work:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Ascribe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">ascribe</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="bp">Self</span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"> </span><span class="bp">self</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">Sized</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Ascribe</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"foo"</span><span class="p">.</span><span class="n">into</span><span class="p">().</span><span class="n">ascribe</span>::<span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213883585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883585">(Oct 20 2020 at 07:34)</a>:</h4>
<p>Would be interesting if it were possible to have a chainable identity function that allows turbofish like that.</p>



<a name="213883701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883701">(Oct 20 2020 at 07:36)</a>:</h4>
<p>Yeah, I suppose it is more appropriate for the grammar to use turbofish than put the type in parens, although now it's getting a bit verbose</p>



<a name="213883749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883749">(Oct 20 2020 at 07:36)</a>:</h4>
<p>but especially if both options are available, it seems like a decent tradeoff: either use the verbose but chainable syntax or the one that requires surrounding parens</p>



<a name="213883798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883798">(Oct 20 2020 at 07:37)</a>:</h4>
<p>I was thinking of <code>x.as&lt;T&gt;</code> or <code>x.as::&lt;T&gt;</code></p>



<a name="213883896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213883896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213883896">(Oct 20 2020 at 07:38)</a>:</h4>
<p>for options that use "as" in the name, I think we would have to somehow unify this with <code>as</code> casting, because otherwise the disconnect would be too confusing</p>



<a name="213897224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213897224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213897224">(Oct 20 2020 at 10:01)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> for the case of <code>into()</code>, you can use the following helper trait:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Into_</span><span class="w"> </span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">into_</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;</span><span class="w"> </span><span class="p">(</span><span class="bp">self</span>: <span class="nc">Self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">U</span><span class="w"></span>
<span class="w">    </span><span class="k">where</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="w"> </span>: <span class="nb">Into</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">into</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Into_</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"Hello, World!"</span><span class="p">.</span><span class="n">into_</span>::<span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>I have made my own attempt to have an <code>.as_::&lt;...&gt;()</code> helper, but since it kind of leads to a chain of inference Rust is still confused about it:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">As_</span><span class="w"> </span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">as_</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span>: <span class="nc">Is</span><span class="o">&lt;</span><span class="n">EqTo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">(</span><span class="bp">self</span>: <span class="nc">Self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="bp">self</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">As_</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="s">"foo"</span><span class="p">.</span><span class="n">into</span><span class="p">().</span><span class="n">as_</span>::<span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="c1">// still does not work</span>
</code></pre></div>

<ul>
<li><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a4e160358b48c2c69bdd387d8654f2f2">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a4e160358b48c2c69bdd387d8654f2f2</a></li>
</ul>
<hr>
<p>Back to the topic at hand, if inference / trait solving was made smart enough for <code>As_</code> above to work, it would already be a big win that would render type ascription kind of "not that needed".</p>
<p>The one place where I would like and welcome type ascription is within patterns: that's where you can use type ascription to help make the code more readable (there is a reason IDEs already do this), and there even have been some suggestions that have built on top of it, such as enums with "anonymous variants" (not saying the suggestions have to necessarily be used, but it kind of shows the potential usefulness of ascription within patterns).</p>
<p>And that is a case where "adding its own binding" does not lead to cleaner code.</p>



<a name="213898668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213898668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213898668">(Oct 20 2020 at 10:16)</a>:</h4>
<p>Addendum: another option, simpler than making <code>As_</code> work, is what I call "copy the generic from trait position to method position", which, with our previous example, would have been bundling the <code>into_</code> logic within the <code>Into</code> trait. The issue with that pattern at the moment, is that bounds such as <code>U : Is&lt;EqTo = T&gt;</code> lead <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=74e668546d7d220c58f157cdbb8cb025">to type inference errors even when <code>T</code> is know</a>.<br>
If that last issue was solved, then library authors with generics parameters in trait position would be able to offer the chance to users to specify what that generic param is with an added generic param added to the method that needs to be <code>EqTo</code> the outer one.</p>
<p>Not as pretty as a more general-purpose <code>.as_</code>, but may be simpler to implement, and in practice it could help a lot with most of these situations. But the lack-of-inference-leading-to-the-generic-param-<strong>needing</strong>-to-be-specified is a bummer in that regard</p>



<a name="213906880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213906880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213906880">(Oct 20 2020 at 11:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/213862866">said</a>:</p>
<blockquote>
<p>I feel with <code>let x: T</code> existing it's hard to pick any <em>other</em> syntax.</p>
<p>That said, I've pondered making <code>x as T</code> be ascription in an edition change.  We're getting closer and closer to having everything it can do have more targeted library methods instead (<code>.cast()</code> on pointers, <code>transmute!</code>, <code>.into()</code>, etc).  So that would potentially open up that syntax instead.</p>
</blockquote>
<p>My opinion is that type ascription (as an expression which takes an expression and a type) doesn't carry its wait, and we should instead consider more limited locations in which a user can insert a type (similar to the ability to insert a type in let bindings and turbofishes today). I don't think we should come up with an alternative syntax for type ascription as is.</p>



<a name="213912273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213912273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213912273">(Oct 20 2020 at 12:41)</a>:</h4>
<p>Interesting thoughts. I too have some significant reservations about <code>x: T</code> syntax, and have long wanted it to be a more "method like" syntax (like <code>foo.as&lt;T&gt;</code>). I don't in general like "open-ended" types that don't have a closing delimiter (although we have that same problem with <code>as</code>). I do find I want it sometimes for calls to <code>collect</code> and other such cases. </p>
<p>Is there a canonical list of the places where type ascription is desired? This might be another good thing to add to the lang-team design notes. =) In particular, if we were going to try and pursue more limited places for annotation, as <span class="user-mention" data-user-id="256759">@boats</span> suggested, it'd be useful to know what kinds of things people want to be able to annotate. The main one I know of is "method return type", which really seems to suggest to me that a general "ascribe type of this expression" is the best way to handle it. (I guess that another use case is triggering coercions to a <code>dyn</code> type?)</p>



<a name="213912508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213912508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213912508">(Oct 20 2020 at 12:43)</a>:</h4>
<p>Based on this thread I wonder if removing type ascription syntax for now would make sense.</p>



<a name="213914412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213914412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213914412">(Oct 20 2020 at 12:58)</a>:</h4>
<p>I've most wanted it in match heads, things like <code>match &amp;foo: &amp;str</code> seem clearer and more obvious to me than <code>match &amp;foo[..]</code> or <code>match &amp;*foo</code></p>



<a name="213914438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213914438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213914438">(Oct 20 2020 at 12:58)</a>:</h4>
<p>Though I'd also tbh like it even more if you could infer the deref coercion from the pattern type</p>



<a name="213935331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213935331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213935331">(Oct 20 2020 at 15:23)</a>:</h4>
<blockquote>
<p>Suppose I want to write <code>A::b(...).c(...).d(...).e(...)</code>, except I need ascription in one or two places before a call.</p>
</blockquote>
<p><a href="https://github.com/rust-lang/rfcs/issues/2522">rfc#2522</a> introduced <code>A::b(...).c(...):U.d(...).e(...):X</code>, or with line breaks,</p>
<div class="codehilite"><pre><span></span><code>A::b(...)
    .c(...): U
    .d(...)
    .e(...): X;
</code></pre></div>


<p>( but 2522 was postponed because of the 5 concerns in <a href="https://github.com/rust-lang/rfcs/pull/2522#issuecomment-415551732">https://github.com/rust-lang/rfcs/pull/2522#issuecomment-415551732</a> <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span> )</p>



<a name="213935748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213935748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213935748">(Oct 20 2020 at 15:26)</a>:</h4>
<blockquote>
<p>given <code>.await</code> as something that has landed in the meantime</p>
<p>"method like" syntax (like <code>foo.as&lt;T&gt;</code>).</p>
</blockquote>
<p>What <em>prevents</em> <code>.as&lt;T&gt;</code>? There's an amount of precedent for not-method method-like things now with <code>.await</code> after all.</p>



<a name="213936058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213936058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213936058">(Oct 20 2020 at 15:29)</a>:</h4>
<p>should it be a fish for consistency with normal generic function calls <code>a.b::&lt;T&gt;().as::&lt;U&gt;()</code> <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="213936219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213936219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213936219">(Oct 20 2020 at 15:30)</a>:</h4>
<p>I was also thinking that, but I know people keep trying to gut the fish.</p>



<a name="213936700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213936700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213936700">(Oct 20 2020 at 15:33)</a>:</h4>
<p>imo if the only difference between <code>a.as&lt;T&gt;</code> and <code>a as T</code> is operator precedence, it's better to fix the precedence than introducing a new syntax</p>
<p>(also, strong oppose if <code>a.as&lt;T&gt;</code> and <code>a as T</code> are both valid and have different semantics)</p>



<a name="213940506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213940506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213940506">(Oct 20 2020 at 16:01)</a>:</h4>
<p>If we can make <code>as</code> do type ascription (with or without the <code>e.as&lt;T&gt;</code> notation), then I think we don't really need <code>e: T</code> type ascription. And <code>as</code> has been in rust forever so it's much easier to train people to use it for type ascription as compared to introducing a new syntax. (If <code>e.as&lt;T&gt;</code> syntax is introduced, then like <span class="user-mention silent" data-user-id="125254">kennytm</span> I think it <em>must</em> be a synonym for <code>e as T</code>.) But that might be tricky because if we don't actually know whether it's a type ascription or a coercion then the type inference problem becomes harder. Additionally, merging the two might cause a danger where something that was supposed to be a type ascription is in fact performing an <code>as</code> cast.</p>



<a name="213946353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213946353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213946353">(Oct 20 2020 at 16:44)</a>:</h4>
<p><code>.become&lt;T&gt;</code> :troll:</p>



<a name="213953245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213953245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213953245">(Oct 20 2020 at 17:33)</a>:</h4>
<p>Type casting: <code>x as T</code> or maybe <code>x.as&lt;T&gt;</code> or <code>x.as::&lt;T&gt;</code></p>
<p>Type ascription: <code>x.type&lt;T&gt;</code> or <code>x.type::&lt;T&gt;</code></p>



<a name="213958584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213958584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213958584">(Oct 20 2020 at 18:11)</a>:</h4>
<p>I like <code>as</code> doing casts, and not merely type assertions. I realize that both of these can technically be described as "type coercion", but one is "strong" and the other is "weak". I would find it much harder to understand <em>why</em> someone wrote <code>as</code> if it was both a strong and weak coercion. I would rather <code>as</code> become more capable of casting non-primitive types than it became a type coercion in some cases.</p>



<a name="213967631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213967631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213967631">(Oct 20 2020 at 19:22)</a>:</h4>
<p>That's absolutely fair.</p>



<a name="213967697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213967697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213967697">(Oct 20 2020 at 19:23)</a>:</h4>
<p>I do use <code>as</code> casts when I really do want to forcibly cast a numeric type. And I generally want type ascription for cases where I'd like to get an error if what I'm doing would have required an <code>as</code>.</p>



<a name="213984582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213984582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213984582">(Oct 20 2020 at 21:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/213967697">said</a>:</p>
<blockquote>
<p>I do use <code>as</code> casts when I really do want to forcibly cast a numeric type. And I generally want type ascription for cases where I'd like to get an error if what I'm doing would have required an <code>as</code>.</p>
</blockquote>
<p>My general thought here is that "forcibly" (lossy) cast should be a method, just like the lossless <code>From</code> is.  Because having syntax for the more-error-pront one but not for the information-preserving one seems backwards.  Hence <code>.wrapping_into()</code> (<a href="https://github.com/rust-lang/rfcs/pull/2484">https://github.com/rust-lang/rfcs/pull/2484</a>) for every combination of integer types, for example.</p>



<a name="213999893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/213999893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#213999893">(Oct 21 2020 at 01:44)</a>:</h4>
<p>One of the things noted in the portable SIMD group is that <code>as</code> makes casts very terse in math ops, which is very useful in many cases... in particular, the enum-&gt;integer casts that happen in a lot of embedded code is another place I've seen it used a lot. We were discussing it because of the tension between wanting adding an f32 to every lane in an f32x4 being explicit vs. being terse, basically "should we impl Add&lt;f32&gt; for f32x4 or should we make that go through a type cast?" The verbosity of method casts, and the fact that integers get to take a shortcut, was in the "con" pile for the type cast route.</p>



<a name="214097602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/214097602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#214097602">(Oct 21 2020 at 18:55)</a>:</h4>
<p>Maybe it would make more sense to use <code>-&gt; T</code>. <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="219193685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219193685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219193685">(Dec 08 2020 at 10:58)</a>:</h4>
<p>Hey <span class="user-group-mention" data-user-group-id="1977">@T-lang</span> -- I am reviewing <span class="user-mention" data-user-id="328097">@BN</span>'s excellent PR <a href="https://github.com/rust-lang/rust/issues/79730">#79730</a>, which implements the "type ascription coercion" fix that has been blocking stabilization (although we recently had a conversation that suggests that people may have lukewarm feelings on ascription).</p>
<p>In so doing, though, I had a thought. I wonder if it would make sense to just forbid type ascriptions on place expressions (i.e., lvalues). So for example this would be illegal:</p>
<div class="codehilite"><pre><span></span><code>let x = 22;
use(x: i32);
</code></pre></div>
<p>We would then say that type ascriptions <em>always</em> enable (implicit) coercions.</p>
<p>This would sidestep the unsoundness, which was specific to a case like <code>&amp;mut (x: &amp;'a i32)</code>, where you are borrowing a place expression <em>and</em> ascribing it a type.</p>
<p>There is also just relatively little reason to ascribe a type to a place expression, since you can always influence its type by ascribing the type on a local variable.</p>



<a name="219193834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219193834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219193834">(Dec 08 2020 at 11:00)</a>:</h4>
<p>I will say that while I was on the fence for a time I am starting to get enthusiastic about the idea of stabilizing type ascription. I feel like the <code>: T</code> syntax is the only obvious one and the interactions around ascription come up constantly. Having a nice replacement for <code>as</code> as well as a nicer way to constrain things like <code>.collect(): T</code> would be great. My main concern though is that it is not a convenient syntax as part of method <em>chains</em> -- i.e., </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">foo</span><span class="w"></span>
<span class="w">    </span><span class="p">.</span><span class="n">bar</span><span class="p">()</span>: <span class="nc">T</span><span class="w"></span>
<span class="w">    </span><span class="p">.</span><span class="n">baz</span><span class="p">()</span><span class="w"></span>
</code></pre></div>
<p>Well, I guess that might actually parse ok, so long as we accept that <code>.</code> is not ever going to be part of type.</p>



<a name="219198780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219198780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219198780">(Dec 08 2020 at 12:04)</a>:</h4>
<p>Could you modify that first example? Is <code>use</code> supposed to be a function call there?</p>



<a name="219198945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219198945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219198945">(Dec 08 2020 at 12:06)</a>:</h4>
<p>/me is feeling very dumb, as in “um are function call argument expressions l-values... ? I would understand <code>x: i32 = 3;</code> or <code>&amp;x: i32</code>”</p>



<a name="219199396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199396">(Dec 08 2020 at 12:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219198780">said</a>:</p>
<blockquote>
<p>Could you modify that first example? Is <code>use</code> supposed to be a function call there?</p>
</blockquote>
<p>yes, sorrry</p>



<a name="219199398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199398">(Dec 08 2020 at 12:13)</a>:</h4>
<p>I can't edit it now I think</p>



<a name="219199428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199428">(Dec 08 2020 at 12:13)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> place expressions (lvalues) are basically expressions of the form</p>
<div class="codehilite"><pre><span></span><code>PE = Local Variable
    | PE.f
    | *expr
</code></pre></div>



<a name="219199434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199434">(Dec 08 2020 at 12:13)</a>:</h4>
<p>i.e., something that names a place in memory</p>



<a name="219199481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199481">(Dec 08 2020 at 12:14)</a>:</h4>
<p>or "something that can appear on the left-hand side of an assignment"</p>



<a name="219199514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199514">(Dec 08 2020 at 12:14)</a>:</h4>
<p>but I realize that, having said this, I want to think a bit more about the exact def'n as it applies here:)</p>



<a name="219199654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199654">(Dec 08 2020 at 12:16)</a>:</h4>
<p>For some reason I had thought it was sensitive to the context in the syntax-tree</p>



<a name="219199682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199682">(Dec 08 2020 at 12:17)</a>:</h4>
<p>I.e. of course <code>x</code> is an l-value. But is it still an l-value when it appears in <code>foo(x)</code>? I guess it depends on one’s grammar.</p>



<a name="219199714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199714">(Dec 08 2020 at 12:17)</a>:</h4>
<p>I guess also the emphasis is that its “something that <em>can</em> appear on the LHS”</p>



<a name="219199775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199775">(Dec 08 2020 at 12:18)</a>:</h4>
<p>(I clearly need to re-read the problem we’re trying to resolve by adding this restriction.)</p>



<a name="219199855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219199855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219199855">(Dec 08 2020 at 12:19)</a>:</h4>
<p>I've also been confused by that <code>use</code>, <span class="user-mention" data-user-id="116083">@pnkfelix</span>, but the <code>&amp;mut (x: &amp;'a i32)</code> example hints at that <code>use</code> not representing a function call but a usage of the place (maybe <code>use_place!(x: i32)</code> would have made that clearer?)</p>
<p>Also, to clarify these nuances, and regarding <code>&amp;mut (x: &amp;'a i32)</code> being forbidden: would <code>&amp;mut { x: &amp;'a i32 }</code> and <code>&amp;mut ({x}: &amp;'a i32)</code> be allowed? These would be performing a place-to-value conversion (?/coercion?/operation?) and then it would be similar to doing <code>&amp;mut identity::&lt;&amp;'a i32&gt;(x)</code> (modulo reborrowing _vs._ move due to type inference interactions).</p>



<a name="219200629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219200629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219200629">(Dec 08 2020 at 12:28)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span> for not allowing ascription of place expressions.</p>



<a name="219204725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219204725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219204725">(Dec 08 2020 at 13:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219199654">said</a>:</p>
<blockquote>
<p>For some reason I had thought it was sensitive to the context in the syntax-tree</p>
</blockquote>
<p>so-- whether something is <em>interpreted</em> as an lvalue is sensitive to its location, that is true. But the property I'm going for is what <em>could</em> be interpreted.</p>
<p>In other words, the original type ascription proposal said that "ascription can coerce but not in certain positions". The reason for this was that it is inappropriate to coerce in an "lvalue context" (left-hand-side of an assignment, or borrow expression, but the borrow could be implicit due to autoref). I am proposing a different thing, which says "ascription can always coerce but cannot be applied to place expressions". This avoids the problem of lvalue contexts because those are only relevant to place expressions.</p>



<a name="219204843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219204843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219204843">(Dec 08 2020 at 13:16)</a>:</h4>
<p>To answer <span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span>'s questions:</p>
<ul>
<li><code>&amp;mut (x: &amp;'a i32)</code> -- disallowed, because <code>x: &amp;'a i32</code> is disallowed in any context. </li>
<li><code>&amp;mut { x: &amp;'a i32 }</code> -- as above.</li>
<li><code>&amp;mut ({x}: &amp;'a i32)</code> -- allowed, because <code>{x}</code> is not equivalent to <code>x</code>. The former is not a place expression. <code>(x)</code> is, though.</li>
</ul>



<a name="219204864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219204864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219204864">(Dec 08 2020 at 13:17)</a>:</h4>
<p>In other words, <code>&amp;x</code> and <code> &amp;{x}</code> are not equivalent.</p>



<a name="219204885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219204885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219204885">(Dec 08 2020 at 13:17)</a>:</h4>
<p>The latter is kind of equivalent to:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">tmp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="o">&amp;</span><span class="n">tmp</span><span class="w"></span>
</code></pre></div>



<a name="219206367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219206367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219206367">(Dec 08 2020 at 13:33)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> isn’t there a middle ground between the two positions you laid out above, namely: disallow ascription in l-value <em>contexts</em> rather than on all l-value expressions?</p>



<a name="219206509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219206509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219206509">(Dec 08 2020 at 13:34)</a>:</h4>
<p>That seems like it directly addresses the problem, while not disallowing potentially useful things like <code>foo(x.y: i32)</code></p>



<a name="219206561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219206561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219206561">(Dec 08 2020 at 13:35)</a>:</h4>
<p>Hmm. Yes, that is an option too</p>



<a name="219206594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219206594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219206594">(Dec 08 2020 at 13:35)</a>:</h4>
<p>And I guess that wouldn't be too hard to implement</p>



<a name="219206671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219206671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219206671">(Dec 08 2020 at 13:36)</a>:</h4>
<p>one challenge I see is that something like <code>(x:i32).y()</code> <em>might</em> be an lvalue context -- but actually we could enforce this rule <strong>after</strong> type-checking</p>



<a name="219206675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219206675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219206675">(Dec 08 2020 at 13:36)</a>:</h4>
<p>when we know for sure</p>



<a name="219237186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219237186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219237186">(Dec 08 2020 at 17:37)</a>:</h4>
<p>Hmm, I'm unsure exactly how to tell that something is an lvalue context.  The <code>&amp;(x:i32)</code> is the weirdest one that comes to mind -- I could imagine it as a place context (just annotating the type) or as an operand context (like in <code>&amp;(x+x)</code>).</p>



<a name="219237292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219237292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219237292">(Dec 08 2020 at 17:38)</a>:</h4>
<p>I suppose that needing to type <code>&amp;({x}:i32)</code> isn't fun, but it might be rare enough to not care.</p>



<a name="219240908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219240908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219240908">(Dec 08 2020 at 18:07)</a>:</h4>
<p>I like this plan rather a lot, because I also think "is an lvalue" is a good heuristic for where additional ascription is probably unwanted / unnecessary. Namely, if you're ascribing a named variable, it'd probably be better to add the ascription at the variable definition site, rather than at the usage site. However, I'm not sure how "arbitrary" it'd feel to users-- I don't think Rust users typically have a good mental model for what things are lvalues and what are not. This is slightly concerning to me, as it reminds me of the random-feeling rules for temporary lifetimes (though those are surprising in ways that can give runtime behavior, so I think this case is less concerning to me since it would only result in compile-time errors).</p>



<a name="219241318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219241318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BN <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219241318">(Dec 08 2020 at 18:11)</a>:</h4>
<p><code>nikomatsakis</code> wrote:</p>
<blockquote>
<p>This would sidestep the unsoundness, which was specific to a case like &amp;mut (x: &amp;'a i32), where you are borrowing a place expression and ascribing it a type.</p>
</blockquote>
<p>Can you explain why this is still necessary? I thought that only coercing type ascriptions inside coercion sites would have solved that problem. Also wouldn't forbidding type ascriptions on lvalues contradict this statement?</p>
<blockquote>
<p>I feel like the : T syntax is the only obvious one and the interactions around ascription come up constantly. Having a nice replacement for <code>as</code> ...</p>
</blockquote>



<a name="219254096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219254096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219254096">(Dec 08 2020 at 19:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328097">BN</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219241318">said</a>:</p>
<blockquote>
<p>I thought that only coercing type ascriptions inside coercion sites would have solved that problem. </p>
</blockquote>
<p>It will, I am proposing an alternative solution. The advantage is that it is easier to code. I am not sure if it's easier to <em>explain</em> to users though.</p>



<a name="219254123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219254123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219254123">(Dec 08 2020 at 19:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219240908">said</a>:</p>
<blockquote>
<p>However, I'm not sure how "arbitrary" it'd feel to users</p>
</blockquote>
<p>Yes, this is the question</p>



<a name="219254190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219254190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219254190">(Dec 08 2020 at 19:58)</a>:</h4>
<p>One thing I was also thinking is that expressions like <code>foo(x).y</code> are technically "lvalues", but we could probably permit them to be coerced.</p>



<a name="219254291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219254291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219254291">(Dec 08 2020 at 19:59)</a>:</h4>
<p>So the set of expressions would probably be precisely those things that match this grammar:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">LV</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">variable</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">LV</span><span class="p">.</span><span class="n">f</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="o">*</span><span class="n">LV</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="p">(</span><span class="n">LV</span><span class="p">)</span><span class="w"></span>
</code></pre></div>



<a name="219254297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219254297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219254297">(Dec 08 2020 at 19:59)</a>:</h4>
<p>well...am I talking nonsense...that seems a bit fishy</p>



<a name="219254304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219254304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219254304">(Dec 08 2020 at 19:59)</a>:</h4>
<p>I think what I'm saying may technically be true but the reasoning is kind of sketchy</p>



<a name="219254350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219254350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219254350">(Dec 08 2020 at 19:59)</a>:</h4>
<p>in particular <code>&amp;foo(x).y</code> will create a temporary to store <code>foo(x)</code>, but it still seems weird to permit a coercion on the type of <code>&lt;tmp&gt;.y</code> that gets borrowed</p>



<a name="219298585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219298585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219298585">(Dec 09 2020 at 05:06)</a>:</h4>
<p>Wait, I thought this was about lvalue "sites", not lvalue expressions. For the former, the context determines whether this is being used as an lvalue, as in <code>&amp;mut _</code> or <code>*_ = ...</code>. These are where lvalues are <em>required</em> and a temporary is used if the input is not already an lvalue. Erroring if type ascription is used here makes good sense to me. But now it sounds like you want to error on all lvalue expressions, even if they are being used as rvalues, and that sounds like it will cause a lot of false positives, for example <code>foo(x.bar: T)</code> or <code>(vec.x: u32) + (vec.y: u32)</code>, or just plain variable references as in:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="kt">u32</span> <span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">();</span><span class="w"></span>
<span class="n">bar</span><span class="p">((</span><span class="n">x</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">);</span><span class="w"></span>
<span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"></span>
</code></pre></div>
<p>(Here I don't want to change the type of <code>x</code> and introduce unsafe on line 3, and I want to use coercion on line 2 because clippy gives me grief otherwise.)</p>



<a name="219298758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219298758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219298758">(Dec 09 2020 at 05:10)</a>:</h4>
<p>I think that the error that one gets for using type ascription at an lvalue site is also quite reasonably actionable: the error message just suggests to replace e.g. <code>&amp;mut (x: T)</code> with <code>&amp;mut {x: T}</code> and not much harm is done to the expression (and it's also reasonably explicit about borrowing a temporary, at least if one is familiar with the idiom <code>{x}</code> for moving).</p>



<a name="219352073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219352073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219352073">(Dec 09 2020 at 15:32)</a>:</h4>
<p>There seem to be 3 proposals on the table:</p>
<ul>
<li>Change semantics of ascription to disallow coercion in lvalue contexts</li>
<li>Forbid ascription of "place expressions" altogether</li>
<li>Forbid ascription of "place expressions" altogether in lvalue contexts</li>
</ul>
<p>(I am going to adopt the term <em>lvalue context</em> to refer to the expression <code>E</code> in assignments <code>E = ...</code>, borrows (<code>&amp;E</code>, <code>&amp;mut E</code>), and auto-ref'd method calls <code>E.foo()</code>. <em>Place expression</em> refers to an expression that references an existing place, which is also one that could appear on the left-hand side of an assignment. Note that the other lvalue contexts (besides assignment) accept arbitrary expressions, but they introduce temporaries if the expression is not a place expression.)</p>



<a name="219352088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219352088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219352088">(Dec 09 2020 at 15:32)</a>:</h4>
<p>I think the final semantics is probably the best one, honestly</p>



<a name="219352967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219352967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219352967">(Dec 09 2020 at 15:38)</a>:</h4>
<p>So if we wanted to use coercion to get a method call, that would be <code>{&amp;mut x: &amp;mut T}.foo()</code>?</p>



<a name="219353323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219353323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219353323">(Dec 09 2020 at 15:40)</a>:</h4>
<p>actually I'm not sure if that works now, does moving a mut reference always turn into a reborrow?</p>



<a name="219354021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219354021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219354021">(Dec 09 2020 at 15:44)</a>:</h4>
<p>hm, I could see scope for an exception specifically for the form <code>(x:T).foo()</code>, perhaps to control auto-deref? There are a few options for what to do there</p>



<a name="219375009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219375009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219375009">(Dec 09 2020 at 18:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219353323">said</a>:</p>
<blockquote>
<p>actually I'm not sure if that works now, does moving a mut reference always turn into a reborrow?</p>
</blockquote>
<p>Looks like it does? <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=13f65afe9c7a34dbef626f71919b6805">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=13f65afe9c7a34dbef626f71919b6805</a></p>
<p>That's not what I was expecting to happen, though...</p>



<a name="219386004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219386004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219386004">(Dec 09 2020 at 19:30)</a>:</h4>
<p>You have to have both a dereference and a move of either the resulting value or the reference to inhibit reborrowing, ie <code>&amp;mut *{x}</code> or <code>&amp;mut {*x}</code></p>



<a name="219386415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219386415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219386415">(Dec 09 2020 at 19:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219352088">said</a>:</p>
<blockquote>
<p>I think the final semantics is probably the best one, honestly</p>
</blockquote>
<p>Agreed.</p>
<p>Then (sorry to go back at this, but to me, it's completely related to this "place expressions" _vs._ "place expression in lvalue context" distinction), <code>&amp;mut { x: &amp;'a i32 }</code> would be <em>allowed</em> (<em>i.e.</em>, there would be no distinction between <code>({ place }: ty)</code> and <code>{ place: ty }</code>), right? . Since we have a place expression <code>x: &amp;'a i32</code> which then, due to the braced block, leaves the "lvalue context" to become a value expression, which gets anonymous-local-promoted to become a place from which we can fetch a <code>&amp;mut</code>. As showcased by:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="o">*</span><span class="p">(</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span><span class="w"></span>
<span class="o">*</span><span class="p">(</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">{</span><span class="n">x</span><span class="p">}</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">27</span><span class="p">;</span><span class="w"></span>
<span class="n">assert_eq</span><span class="o">!</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="219388363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219388363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219388363">(Dec 09 2020 at 19:47)</a>:</h4>
<p>in your example, <code>x</code> has type <code>i32</code>, not <code>&amp;i32</code></p>



<a name="219388399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219388399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219388399">(Dec 09 2020 at 19:47)</a>:</h4>
<p>so <code>*(&amp;mut {x: &amp;i32}) += 42</code> would not be valid</p>



<a name="219388795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219388795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219388795">(Dec 09 2020 at 19:50)</a>:</h4>
<blockquote>
<p>there would be no distinction between ({ place }: ty) and { place: ty }), right?</p>
</blockquote>
<p>With option 3, there would be a difference between these: <code>&amp;mut ({ place }: ty)</code> would not be allowed because the type ascription is in an lvalue context</p>



<a name="219389262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219389262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219389262">(Dec 09 2020 at 19:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219354021">said</a>:</p>
<blockquote>
<p>hm, I could see scope for an exception specifically for the form <code>(x:T).foo()</code>, perhaps to control auto-deref? There are a few options for what to do there</p>
</blockquote>
<p>Also, it's worth pointing out that adding an exception for method calls would not interfere with the generic rules of option 3 (or option 2) as it would only make some errors no longer an error, so it is safe to defer this choice to later as an "ergonomics pass" if the initial version is successful</p>



<a name="219390756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219390756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219390756">(Dec 09 2020 at 20:07)</a>:</h4>
<p>We call them place expression contexts in the reference, not lvalue contexts: <a href="https://doc.rust-lang.org/stable/reference/expressions.html#place-expressions-and-value-expressions">https://doc.rust-lang.org/stable/reference/expressions.html#place-expressions-and-value-expressions</a></p>



<a name="219390885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219390885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219390885">(Dec 09 2020 at 20:09)</a>:</h4>
<p>But yes, using a place expression in a value expression context creates a temporary.</p>



<a name="219705474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/219705474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#219705474">(Dec 12 2020 at 12:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/219388363">said</a>:</p>
<blockquote>
<p>in your example, <code>x</code> has type <code>i32</code>, not <code>&amp;i32</code></p>
</blockquote>
<p>I was demoing the temporaries behavior, with <code>&amp;i32</code>s it would have been a bit more annoying to write <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="220681748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/type%20ascription/near/220681748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/type.20ascription.html#220681748">(Dec 22 2020 at 11:52)</a>:</h4>
<p>I created <a class="stream" data-stream-id="269230" href="/#narrow/stream/269230-t-lang.2Ftype-ascription">#t-lang/type-ascription</a> to work on the type ascription implementaton etc</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>